import { http } from '@/utils/request'
import type {
  Material,
  MaterialAddRequest,
  MaterialUpdateRequest,
  MaterialQueryRequest,
  UpdateRequest,
  BaseResponse,
  PageResponse
} from '@/types'

// 创建物料
export const createMaterial = (data: MaterialAddRequest): Promise<BaseResponse<number>> => {
  return http.post('/material/add', data)
}

// 更新物料
export const updateMaterial = (data: MaterialUpdateRequest): Promise<BaseResponse<boolean>> => {
  return http.post('/material/update', data)
}

// 分页获取物料列表
export const getMaterialList = (data: MaterialQueryRequest): Promise<BaseResponse<PageResponse<Material>>> => {
  return http.post('/material/list/page', data)
}

// 获取库存预警物料
export const getWarningMaterials = (): Promise<BaseResponse<Material[]>> => {
  return http.post('/material/list/warning')
}

// 根据ID获取物料
export const getMaterial = (data: UpdateRequest): Promise<BaseResponse<Material>> => {
  return http.post('/material/get', data)
}

// 删除物料
export const deleteMaterial = (data: UpdateRequest): Promise<BaseResponse<boolean>> => {
  return http.post('/material/delete', data)
}
